﻿@model AdminUserEditGetViewModel
@{
    ViewBag.Title = "编辑管理员";
}

<article class="page-container">
    <form class="form form-horizontal" id="form-admin-add">
        <input type="hidden" name="id" value="@Model.User.Id" />
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员：</label>
            <div class="formControls col-xs-8 col-sm-9">
                @Model.User.Name
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">初始密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="password" name="password">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">确认密码：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="password" class="input-text" autocomplete="off" placeholder="确认新密码" id="password2" name="password2">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>手机：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.User.PhoneNum" placeholder="" id="phoneNum" name="phoneNum">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>邮箱：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="@Model.User.Email" placeholder="@Html.Raw("@")" name="email" id="email">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">角色：</label>
            <div class="formControls col-xs-8 col-sm-9 check-box-list">
                @foreach (var role in Model.AllRoles)
                {
                    <label for="role_@role.Id" class="col-xs-4">
                        <input type="checkbox" class="checkbox" id="role_@role.Id" value="@role.Id" name="adminRoles[]" checked="@Model.User.RoleIds.Contains(role.Id)">@role.Name
                    </label>
                }
                <label id="adminRoles[]-error" class="col-xs-4 error" for="adminRoles[]">未设置用户角色</label>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-primary radius" id="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
            </div>
        </div>
    </form>
</article>

@section FooterScript
{
    <!--请在下方写此页面业务相关的脚本-->
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="~/Areas/WebAdmin/FrontLib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#form-admin-add").validate({
                rules: {
                    password2: {
                        equalTo: "#password"
                    }
                    //"adminRoles[]": {
                    //    required: true
                    //}
                    //phoneNum: {
                    //	required:true,
                    //	isPhone:true,
                    //},
                    //email: {
                    //	required:true,
                    //	email:true,
                    //}
                },
                messages: {
                    //"adminRoles[]": {
                    //    required: '未设置用户角色'
                    //}
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    //禁用保存按钮，防止重复提交
                    $("#submit").prop("disabled", true);

                    $(form).ajaxSubmit({
                        type: 'POST',
                        url: "/WebAdmin/AdminUser/Edit",
                        success: function (res) {
                            if (res.status == "ok") {
                                parent.layer.msg('修改成功!', { icon: 1, time: 1000 }, function () {
                                    parent.$('.btn-refresh').click();
                                    //parent.location.reload(); //刷新父页面
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                });
                            } else if (res.status == "redirect") {
                                location.href = res.data;
                            } else if (res.status == "error") {
                                layer.msg(res.errorMsg, { icon: 2, time: 1000 });
                                //解除禁用
                                $("#submit").prop("disabled", false);
                            } else {
                                layer.msg("修改失败", { icon: 2, time: 1000 });
                                //解除禁用
                                $("#submit").prop("disabled", false);
                            }
                        },
                        error: function (XmlHttpRequest, textStatus, errorThrown) {
                            layer.msg('网络出错!', { icon: 2, time: 1000 });
                            //解除禁用
                            $("#submit").prop("disabled", false);
                        }
                    });
                }
            });
        });
    </script>
    <!--/请在上方写此页面业务相关的脚本-->
}


